#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define in read()
#define pb push_back

const int MAXN = 1e6+10;
const ll inf = 0x3f3f3f3f3f3f3f3f;

int d[MAXN],dfn[MAXN],dep[MAXN],fa[22][MAXN],n,need[MAXN],top,stk[MAXN],tot,k,vis[MAXN],q;
ll ans,f[MAXN],g[MAXN],cnt[MAXN],mn,mx;

struct edge{
	int v,w;
};

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1) + (x<<3) + (ch ^ 48);
	return x * sgn;
}

vector <edge> G[MAXN];

void dfs(int x,int p){
	dep[x] = dep[p] + 1;fa[0][x] = p;dfn[x] = ++tot;
	for(int i = 1;i <= 20;i++) fa[i][x] = fa[i-1][fa[i-1][x]];
	for(int i = 0;i < (int)G[x].size();i++){
		int y = G[x][i].v;
		if(y == p) continue;
		d[y] = d[x] + 1;
		dfs(y,x);
	}
}

int lca(int x,int y){
	if(dep[x] < dep[y]) swap(x,y);
	for(int i = 20;i >= 0;i--){
		if(dep[fa[i][x]] >= dep[y]) x = fa[i][x];
	}
	if(x == y) return x;
	for(int i = 20;i >= 0;i--)
		if(fa[i][x] != fa[i][y])
			x = fa[i][x],y = fa[i][y];
	return fa[0][x];
}

int dis(int x,int y){return d[x] + d[y] - 2 * d[lca(x,y)];}

bool cmp(int x,int y){return dfn[x] < dfn[y];}

void link(int x,int y){G[x].pb(edge{y,dis(x,y)});}

void build(){
	sort(need+1,need+k+1,cmp);
	stk[top=1] = 1;G[1].clear();
	for(int i = 1;i <= k;i++){
		int x = need[i];
		if(x == 1) continue;
		int l = lca(stk[top],x);
		if(l != stk[top]){
			while(dfn[l] < dfn[stk[top-1]]){
				link(stk[top-1],stk[top]);
				top--;
			}
			if(dfn[l] > dfn[stk[top-1]]){
				G[l].clear();
				link(l,stk[top]);
				stk[top] = l;
			}else{
				link(l,stk[top--]);
			}
		}
		G[x].clear(); stk[++top] = x;
	}
	for(int i = 1;i < top;i++) link(stk[i],stk[i+1]);
}

void dp(int x){
	cnt[x] = (vis[x] == q);
	f[x] = vis[x] == q ? 0 : inf;
	g[x] = 0; 
	for(int i = 0;i < (int)G[x].size();i++){
		int y = G[x][i].v,w = G[x][i].w;
		dp(y);
		ans += cnt[y] * (k - cnt[y]) * w;
		if(cnt[x]) mn = min(mn,f[x] + f[y] + w);
		if(cnt[x]) mx = max(mx,g[x] + g[y] + w);
		f[x] = min(f[x],f[y]+w);
		g[x] = max(g[x],g[y]+w);
		cnt[x] += cnt[y];
	}
}
		
int main (){
	memset(vis,-1,sizeof(vis));
	scanf("%d",&n);
	for(int i = 1;i < n;i++){
		int a,b;
		a = in,b = in;
		G[a].pb(edge{b,1});
		G[b].pb(edge{a,1});
	}
	dfs(1,0);
	q = in;
	while(q--){
		k = in;
		for(int i = 1;i <= k;i++) need[i] = in,vis[need[i]] = q;
		build();
		ans = 0;mn = inf;mx = 0;
		dp(1);
		printf("%lld %lld %lld\n",ans,mn,mx);
	}
	return 0;
}
